package org.csu.xzypetstore.controller;

import org.csu.xzypetstore.domain.Account;
import org.csu.xzypetstore.domain.Mylog;
import org.csu.xzypetstore.service.MylogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/catalog")
@SessionAttributes({"myloglist"})
public class maincontroller {


    @Autowired
    private Account account;

    @Autowired
    private MylogService mylogService;

    private String username;
    @GetMapping("/viewmain")
    public String InTo()
    {
        return "catalog/main";
    }

    @GetMapping("/loginView")
    public String loginView()
    {
        return "account/SignonForm";
    }

    @GetMapping("/logView")
    public String logView(HttpServletRequest request, Model model) throws ServletException, IOException
    {
        HttpSession session = request.getSession();
        account = (Account) session.getAttribute("account");
        username = account.getUsername();
        System.out.println(username);
        List<Mylog> mylogList = mylogService.getMylogList(username);
        model.addAttribute("myloglist",mylogList);
        return "account/viewMylog";
    }



}
